package com.mangatta.ec2.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.util.Log;
import com.mangatta.ec2.service.Ec2DataPullerService;

public class NetworkReceiver extends BroadcastReceiver {
    private final static String TAG = NetworkReceiver.class.getSimpleName();

    @Override
    public void onReceive(Context context, Intent intent) {
        boolean isNetworkDown = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
        if (isNetworkDown) {
            Log.d(TAG, "onReceive: NOT connected");
            context.stopService(new Intent(context, Ec2DataPullerService.class));
        } else {
            Log.d(TAG, "onReceived: Connected");
            context.startService(new Intent(context, Ec2DataPullerService.class));
        }
    }
}
